<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: view.html.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class JhtraqViewUsers extends JView {
    function display($tpl = null) {
//    $model =& JhtraqHelper::getModel('jhtraq');
//    print_r($model);

		$task = JRequest::getCmd('task', 'index');
		$tpl = $this->$task();
		
        parent::display($tpl);
    }
	
	function grouplist()
	{
		$_REQUEST['tmpl'] = 'component';
		$model =& JhtraqHelper::getModel('usergroups');
		$this->groups = $model->getPaged();
		$this->pagination = $model->getPagination();
		return 'groups';
	}
	
	function editgroup()
	{
		$_REQUEST['tmpl'] = 'component';
		$model =& JhtraqHelper::getModel('usergroups');
		$this->group = $model->get(JRequest::getVar('id',0));
		return 'groupform';
	}
	
	function savegroup()
	{
		$_REQUEST['tmpl'] = 'component';
		$model =& JhtraqHelper::getModel('usergroups');
		$this->group = $model->get(JRequest::getVar('id',0));
		$this->group->name = JRequest::getVar('name');
		$model->save($this->group);
		$mainframe =& JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=users&task=grouplist", JText::_("COM_JHTRAQ_GROUPS_UPDATED"));
	}
	
	function removegroup()
	{
		$_REQUEST['tmpl'] = 'component';
		$model =& JhtraqHelper::getModel('usergroups');
		$model->remove(JRequest::getVar('id',0));
		$mainframe =& JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=users&task=grouplist", JText::_("COM_JHTRAQ_GROUPS_UPDATED"));
	}
	
	function index()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->users = $model->getUsers();
		$this->pagination = $model->getPagination();
		$this->search = JRequest::getVar('search');
		//print_r($this->settings);
		
	}
	
	function edit()
	{
		$uid = JRequest::getVar('id');
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->user = $model->getUser($uid);
		$this->groups = $model->getUserGroups();
		return 'form';
		//die($uid);
	}
	
	function save()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->user = $model->setUserGroup($_POST['id'],$_POST['group_id']);
		$mainframe =& JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=users", JText::_('COM_JHTRAQ_USER_GROUP_UPDATED'));
	}
	
	/**
	 * cancel editing a record
	 * @return void
	*/
	function cancel()
	{
		$mainframe = JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=users", JText::_('COM_JHTRAQ_OPERATION_CANCELLED'));
	}
	
	
}
?>